#! /bin/sh

. ./prelude

bspc monitor -a "test-insertion"
bspc desktop -f "test-insertion"

# Automatic mode

window add 2

split_type_a=$(bspc query -T -n @/ | jshon -e splitType -u)

window add

split_type_b=$(bspc query -T -n @/2 | jshon -e splitType -u)

[ "$split_type_a" = "$split_type_b" ] && fail "Non-vacant node insertion should rotate brother."

split_type_a=$(bspc query -T -n @/ | jshon -e splitType -u)

bspc rule -a Test:test -o state=floating
window add

split_type_b=$(bspc query -T -n @/2 | jshon -e splitType -u)

[ "$split_type_a" = "$split_type_b" ] || fail "Vacant node insertion shouldn't rotate brother."

window remove

# Manual mode

for dir in north west south east ; do
	child=1
	split_type=vertical
	[ "$dir" = "south" -o "$dir" = "east" ] && child=2
	[ "$dir" = "north" -o "$dir" = "south" ] && split_type=horizontal
	bspc node -p $dir
	window add
	[ "$(bspc query -N -n)" = "$(bspc query -N -n @parent/${child})" ] || fail "Wrong child polarity for ${dir} preselection."
	[ "$(bspc query -T -n @parent | jshon -e splitType -u)" = "$split_type" ] || fail "Wrong split type for ${dir} preselection."
done

window remove 7

bspc desktop "test-insertion" -r
